package com.ricchieri.manage.bean;

import javax.faces.bean.ManagedProperty;

import com.ricchieri.bean.FixedReservationBean;
import com.ricchieri.filter.BasicFilter;
import com.ricchieri.filter.TripFilter;
import com.ricchieri.model.MeanPayment;
import com.ricchieri.model.PassengerType;
import com.ricchieri.model.ReservationType;
import com.ricchieri.model.Trip;
import com.ricchieri.model.User;
import com.ricchieri.service.interf.IMeanPaymentService;
import com.ricchieri.service.interf.IPassengerTypeService;
import com.ricchieri.service.interf.IReservationTypeService;
import com.ricchieri.service.interf.ITripService;

public abstract class CommonFixedReservationManageBean extends GenericManageBean {

	private static final long serialVersionUID = -5907030136425386743L;
	
	@ManagedProperty(value = "#{TripService}")
	ITripService tripService;
	
	@ManagedProperty(value = "#{ReservationTypeService}")
	IReservationTypeService reservationTypeService;
	
	@ManagedProperty(value = "#{PassengerTypeService}")
	IPassengerTypeService passengerTypeService;
	
	@ManagedProperty(value = "#{MeanPaymentService}")
	IMeanPaymentService meanPaymentService;
	
	private FixedReservationBean fixedReservationBean = new FixedReservationBean();
	private User selectedUser;
	
	public void setTripService(ITripService tripService) {
		this.tripService = tripService;
	}

	public IReservationTypeService getReservationTypeService() {
		return reservationTypeService;
	}

	public void setReservationTypeService(IReservationTypeService reservationTypeService) {
		this.reservationTypeService = reservationTypeService;
	}

	public IPassengerTypeService getPassengerTypeService() {
		return passengerTypeService;
	}

	public void setPassengerTypeService(IPassengerTypeService passengerTypeService) {
		this.passengerTypeService = passengerTypeService;
	}

	public IMeanPaymentService getMeanPaymentService() {
		return meanPaymentService;
	}

	public void setMeanPaymentService(IMeanPaymentService meanPaymentService) {
		this.meanPaymentService = meanPaymentService;
	}

	public ITripService getTripService() {
		return tripService;
	}

	public MeanPayment obtainMeanPayment() {
		if(getFixedReservationBean() != null) {
			BasicFilter meanPaymentFilter = new BasicFilter();
			meanPaymentFilter.setId(Integer.valueOf(getFixedReservationBean().getSelectedMeanPayment()));
			return getMeanPaymentService().getMeanPaymentById(meanPaymentFilter);
		} else {
			return null;
		}
	}

	public PassengerType obtainPassengerType() {
		if(getFixedReservationBean() != null) {
			BasicFilter passengerTypeFilter = new BasicFilter();
			passengerTypeFilter.setId(Integer.valueOf(getFixedReservationBean().getSelectedPassengerType()));
			return getPassengerTypeService().getPassengerTypeById(passengerTypeFilter);
		} else {
			return null;
		}
	}

	public ReservationType obtainReservationType() {
		if(getFixedReservationBean() != null) {
			BasicFilter reservationTypeFilter = new BasicFilter();
			reservationTypeFilter.setId(Integer.valueOf(getFixedReservationBean().getSelectedReservationType()));
			return getReservationTypeService().getReservationTypeById(reservationTypeFilter);
		} else {
			return null;
		}
	}

	public Trip obtainTrip() {
		if(getFixedReservationBean() != null) {
			TripFilter tripFilter = new TripFilter();
			tripFilter.setId(Integer.valueOf(getFixedReservationBean().getTrip()));
			return getTripService().getTripById(tripFilter);
		} else {
			return null;
		}
	}

	public FixedReservationBean getFixedReservationBean() {
		return fixedReservationBean;
	}
	
	public void setFixedReservationBean(FixedReservationBean fixedReservationBean) {
		this.fixedReservationBean = fixedReservationBean;
	}
	
	public User getSelectedUser() {
		return selectedUser;
	}
	
	public void setSelectedUser(User selectedUser) {
		this.selectedUser = selectedUser;
	}
}